package com.monad.firemoth.config.satoken;

import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import com.monad.firemoth.config.satoken.interceptor.AuthInterceptor;
import com.monad.firemoth.config.satoken.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 单C胞生物
 * @version 1.0.0
 * @date 2024/4/20 20:32
 * @description Sa-Token 配置类
 */
@Configuration
public class SaTokenConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private AuthInterceptor authInterceptor;

    /**
     * Sa-Token 生成jwt
     */
    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForSimple();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] path = new String[]{
                "/", "/system/login", "/system/oauth/**", "/system/captcha/**",
                "/system/forget", "/system/register",
                "/file/**",
                "/webjars/**", "/v3/**", "/doc.html",
                "/index.html**", "/static/**", "/favicon.ico"
        };
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(path);
        registry.addInterceptor(authInterceptor).addPathPatterns("/**").excludePathPatterns(path);
    }

}
